package com.kfm.ding.service.impl;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import com.kfm.ding.service.DingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class DingServiceImpl implements DingService {

    @Value("${ding.url}")
    private String url;

    @Override
    public void sendMessage(String message) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.set("msgtype", "text");
        JSONObject text = new JSONObject();
        text.set("content", message);
        jsonObject.set("text", text);
        String json = HttpRequest.post(url).body(jsonObject.toString()).header(Header.CONTENT_TYPE, "application/json").execute().body();
        log.info("发送的结果为{}", json);
    }
}
